home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1996 #15 / Monster Media Number 15 (Monster Media)(July 1996).ISO / os2 / memsz313.zip / SOURCE.ZIP / ITEMS.H < prev    next >
Text File  |  1996-04-02  |  16KB  |  515 lines

  1. /******************************************************************** ITEMS.H
  2.  *                                                                          *
  3.  *                     Display Item Class Definition                        *
  4.  *                                                                          *
  5.  ****************************************************************************/
  6.  
  7. #ifndef ITEMS_H
  8. #define ITEMS_H
  9.  
  10. #ifndef OS2_INCLUDED
  11.    #define INCL_BASE
  12.    #define INCL_PM
  13.    #include <os2.h>
  14. #endif
  15.  
  16. #include <time.h>
  17.  
  18. #include "Dde.h"
  19. #include "ReString.h"
  20.  
  21. extern VOID Log ( char *Message, ... ) ;
  22.  
  23. class Item {
  24.  
  25.    private:
  26.       USHORT Id ;                  // Item ID.
  27.       BOOL   Flag ;                // Flag: Show this item at this time?
  28.       char   Name [80] ;           // Text for items profile name.
  29.       char   DefaultLabel [80] ;   // Text to display on left part of line (default).
  30.       Dde_Server *pDdeServer ;     // -> DDE Server object
  31.       char Topic [80] ;            // DDE Topic name
  32.       Dde_Item *pDdeItem ;         // -> DDE Item object
  33.  
  34.    protected:
  35.       char   CurrentLabel [80] ;   // Text to display on left part of line.
  36.       ULONG  Value ;               // Current value.
  37.  
  38.    public:
  39.       Item ( USHORT id, char *pName, char *pCurrentLabel, char *pDefaultLabel, Dde_Server *ddeserver, char *topic ) :
  40.          Id(id), Flag(TRUE), Value(0), pDdeServer(ddeserver) {
  41.          strcpy ( Name, pName ) ;
  42.          strcpy ( CurrentLabel, pCurrentLabel ) ;
  43.          strcpy ( DefaultLabel, pDefaultLabel ) ;
  44.          strcpy ( Topic, topic ) ;
  45.          pDdeServer->AddItem ( Topic, DefaultLabel, DDEFMT_TEXT, "", 1 ) ;
  46.          pDdeItem = pDdeServer->FindItem ( Topic, DefaultLabel ) ;
  47.       }
  48.  
  49.       ~Item ( ) {
  50.          pDdeServer->RemoveItem ( Topic, DefaultLabel ) ;
  51.       }
  52.  
  53.       USHORT QueryId           ( void ) { return ( Id   ) ; }
  54.       BOOL   QueryFlag         ( void ) { return ( Flag ) ; }
  55.       PCHAR  QueryName         ( void ) { return ( Name ) ; }
  56.       PCHAR  QueryCurrentLabel ( void ) { return ( CurrentLabel ) ; }
  57.       PCHAR  QueryDefaultLabel ( void ) { return ( DefaultLabel ) ; }
  58.       ULONG  QueryValue        ( void ) { return ( Value ) ; }
  59.  
  60.       void SetLabel ( char *label ) { strcpy ( CurrentLabel, label ) ;  Value = 0 ; }
  61.  
  62.       void SetFlag   ( void ) { Flag = TRUE ; }
  63.       void ResetFlag ( void ) { Flag = FALSE ; }
  64.  
  65.       void DdeUpdate ( char *Text ) ;
  66.  
  67.       void Paint ( HPS hPS, RECTL &Rectangle, 
  68.          COLOR TextColor, COLOR BackColor,
  69.          char *Label, char *Text, ULONG NewValue ) ;
  70.  
  71.       // The following functions must be provided by all subclasses.
  72.  
  73.       virtual int Measure ( HPS hPS, RECTL &Rectangle ) = 0 ;
  74.  
  75.       virtual ULONG NewValue ( void ) = 0 ;
  76.  
  77.       virtual void FormatText ( char *Label, char *Text, ULONG Value ) = 0 ;
  78.  
  79.       virtual void FormatLine ( char *Buffer, int MaxWidth ) ;
  80.  
  81.       virtual void Repaint ( HPS hPS, RECTL &Rectangle,
  82.          COLOR TextColor, COLOR BackColor, BOOL Mandatory ) = 0 ;
  83. } ;
  84.  
  85. class Clock : public Item {
  86.  
  87.    private:
  88.       COUNTRYINFO CountryInfo ;
  89.       char szAm [8] ;
  90.       char szPm [8] ;
  91.       ResourceString *DaysOfWeek ;
  92.       BOOL ShowSeconds ;
  93.  
  94.    public:
  95.       Clock ( USHORT id, char *pName, char *pCurrentLabel, char *pDefaultLabel, 
  96.          Dde_Server *pDdeServer, char *Topic, COUNTRYINFO &countryinfo,
  97.          char *szam, char *szpm, ResourceString *daysofweek, BOOL showseconds )
  98.  
  99.          : Item ( id, pName, pCurrentLabel, pDefaultLabel, pDdeServer, Topic ),
  100.          DaysOfWeek(daysofweek), ShowSeconds(showseconds) {
  101.  
  102.          CountryInfo = countryinfo ;
  103.  
  104.          memcpy ( szAm, szam, min(strlen(szam),sizeof(szAm)-1) ) ;
  105.          szAm [ sizeof(szAm) - 1 ] = 0 ;
  106.  
  107.          memcpy ( szPm, szpm, min(strlen(szpm),sizeof(szPm)-1) ) ;
  108.          szPm [ sizeof(szPm) - 1 ] = 0 ;
  109.       }
  110.  
  111.       void SetShowSeconds ( BOOL showseconds ) { ShowSeconds = showseconds ; Value = 0 ; }
  112.  
  113.       int Measure ( HPS hPS, RECTL &Rectangle ) ;
  114.  
  115.       ULONG NewValue ( void ) ;
  116.  
  117.       void FormatText ( char *Label, char *Text, ULONG Value ) ;
  118.  
  119.       void FormatLine ( char *Buffer, int MaxWidth ) ;
  120.  
  121.       void Repaint ( HPS hPS, RECTL &Rectangle,
  122.          COLOR TextColor, COLOR BackColor, BOOL Mandatory ) ;
  123. } ;
  124.  
  125. class ElapsedTime : public Item {
  126.  
  127.    private:
  128.       COUNTRYINFO CountryInfo ;
  129.       ResourceString *Day ;
  130.       ResourceString *Days ;
  131.       BOOL ShowSeconds ;
  132.  
  133.    public:
  134.       ElapsedTime ( USHORT id, char *pName, char *pCurrentLabel, char *pDefaultLabel, 
  135.          Dde_Server *pDdeServer, char *Topic, COUNTRYINFO &countryinfo,
  136.          ResourceString *day, ResourceString *days, BOOL showseconds )
  137.  
  138.          : Item ( id, pName, pCurrentLabel, pDefaultLabel, pDdeServer, Topic ),
  139.          Day(day), Days(days), ShowSeconds(showseconds) {
  140.  
  141.          CountryInfo = countryinfo ;
  142.       }
  143.  
  144.       void SetShowSeconds ( BOOL showseconds ) { ShowSeconds = showseconds ;  Value = 0 ; }
  145.  
  146.       int Measure ( HPS hPS, RECTL &Rectangle ) ;
  147.  
  148.       ULONG NewValue ( void ) ;
  149.  
  150.       void FormatText ( char *Label, char *Text, ULONG Value ) ;
  151.  
  152.       void Repaint ( HPS hPS, RECTL &Rectangle,
  153.          COLOR TextColor, COLOR BackColor, BOOL Mandatory ) ;
  154. } ;
  155.  
  156. class SwapFree : public Item {
  157.  
  158.    private:
  159.       COUNTRYINFO CountryInfo ;
  160.       USHORT ShowK ;
  161.       PSZ SwapPath ;
  162.       ULONG MinFree ;
  163.  
  164.    public:
  165.       SwapFree ( USHORT id, char *pName, char *pCurrentLabel, char *pDefaultLabel, 
  166.          Dde_Server *pDdeServer, char *Topic, COUNTRYINFO &countryinfo,
  167.          USHORT sk, PSZ swappath, ULONG minfree )
  168.  
  169.          : Item ( id, pName, pCurrentLabel, pDefaultLabel, pDdeServer, Topic ),
  170.          ShowK(sk), MinFree(minfree) {
  171.  
  172.          CountryInfo = countryinfo ;
  173.          SwapPath = new BYTE [ strlen(PCHAR(swappath)) + 1 ] ;
  174.          strcpy ( PCHAR(SwapPath), PCHAR(swappath) ) ;
  175.       }
  176.  
  177.       ~SwapFree ( void ) {
  178.          delete [] SwapPath ;
  179.       }
  180.  
  181.       void SetShowK ( USHORT flag ) { ShowK = flag ;  Value = 0 ; }
  182.  
  183.       int Measure ( HPS hPS, RECTL &Rectangle ) ;
  184.  
  185.       ULONG NewValue ( void ) ;
  186.  
  187.       void FormatText ( char *Label, char *Text, ULONG Value ) ;
  188.  
  189.       void Repaint ( HPS hPS, RECTL &Rectangle,
  190.          COLOR TextColor, COLOR BackColor, BOOL Mandatory ) ;
  191. } ;
  192.  
  193. class MemoryFree : public Item {
  194.  
  195.    private:
  196.       COUNTRYINFO CountryInfo ;
  197.       USHORT ShowK ;
  198.  
  199.    public:
  200.       MemoryFree ( USHORT id, char *pName, char *pCurrentLabel, char *pDefaultLabel, 
  201.          Dde_Server *pDdeServer, char *Topic, COUNTRYINFO &countryinfo, USHORT sk )
  202.  
  203.          : Item ( id, pName, pCurrentLabel, pDefaultLabel, pDdeServer, Topic ), 
  204.          ShowK(sk) {
  205.  
  206.          CountryInfo = countryinfo ;
  207.       }
  208.  
  209.       void SetShowK ( USHORT flag ) { ShowK = flag ;  Value = 0 ; }
  210.  
  211.       int Measure ( HPS hPS, RECTL &Rectangle ) ;
  212.  
  213.       ULONG NewValue ( void ) ;
  214.  
  215.       void FormatText ( char *Label, char *Text, ULONG Value ) ;
  216.  
  217.       void Repaint ( HPS hPS, RECTL &Rectangle,
  218.          COLOR TextColor, COLOR BackColor, BOOL Mandatory ) ;
  219. } ;
  220.  
  221. class VirtualFree : public Item {
  222.  
  223.    private:
  224.       COUNTRYINFO CountryInfo ;
  225.       USHORT ShowK ;
  226.  
  227.    public:
  228.       VirtualFree ( USHORT id, char *pName, char *pCurrentLabel, char *pDefaultLabel, 
  229.          Dde_Server *pDdeServer, char *Topic, COUNTRYINFO &countryinfo, USHORT sk )
  230.  
  231.          : Item ( id, pName, pCurrentLabel, pDefaultLabel, pDdeServer, Topic ), 
  232.          ShowK(sk) {
  233.  
  234.          CountryInfo = countryinfo ;
  235.       }
  236.  
  237.       void SetShowK ( USHORT flag ) { ShowK = flag ;  Value = 0 ; }
  238.  
  239.       int Measure ( HPS hPS, RECTL &Rectangle ) ;
  240.  
  241.       ULONG NewValue ( void ) ;
  242.  
  243.       void FormatText ( char *Label, char *Text, ULONG Value ) ;
  244.  
  245.       void Repaint ( HPS hPS, RECTL &Rectangle,
  246.          COLOR TextColor, COLOR BackColor, BOOL Mandatory ) ;
  247. } ;
  248.  
  249. class SwapSize : public Item {
  250.  
  251.    private:
  252.       COUNTRYINFO CountryInfo ;
  253.       USHORT ShowK ;
  254.       PSZ SwapPath ;
  255.  
  256.    public:
  257.       SwapSize ( USHORT id, char *pName, char *pCurrentLabel, char *pDefaultLabel, 
  258.          Dde_Server *pDdeServer, char *Topic, COUNTRYINFO countryinfo, 
  259.          USHORT sk, PSZ swappath )
  260.  
  261.          : Item ( id, pName, pCurrentLabel, pDefaultLabel, pDdeServer, Topic ), 
  262.          ShowK(sk) {
  263.  
  264.          CountryInfo = countryinfo ;
  265.          SwapPath = new BYTE [ strlen(PCHAR(swappath)) + 1 ] ;
  266.          strcpy ( PCHAR(SwapPath), PCHAR(swappath) ) ;
  267.       }
  268.  
  269.       ~SwapSize ( void ) {
  270.          delete [] SwapPath ;
  271.       }
  272.  
  273.       void SetShowK ( USHORT flag ) { ShowK = flag ;  Value = 0 ; }
  274.  
  275.       int Measure ( HPS hPS, RECTL &Rectangle ) ;
  276.  
  277.       ULONG NewValue ( void ) ;
  278.  
  279.       void FormatText ( char *Label, char *Text, ULONG Value ) ;
  280.  
  281.       void Repaint ( HPS hPS, RECTL &Rectangle,
  282.          COLOR TextColor, COLOR BackColor, BOOL Mandatory ) ;
  283. } ;
  284.  
  285. class SpoolSize : public Item {
  286.  
  287.    private:
  288.       COUNTRYINFO CountryInfo ;
  289.       USHORT ShowK ;
  290.       PSZ SpoolPath ;
  291.  
  292.    public:
  293.       SpoolSize ( USHORT id, char *pName, char *pCurrentLabel, char *pDefaultLabel, 
  294.          Dde_Server *pDdeServer, char *Topic, COUNTRYINFO &countryinfo, 
  295.          USHORT sk, PSZ spoolpath )
  296.  
  297.          : Item ( id, pName, pCurrentLabel, pDefaultLabel, pDdeServer, Topic ), 
  298.          ShowK(sk) {
  299.  
  300.          CountryInfo = countryinfo ;
  301.          SpoolPath = new BYTE [ strlen(PCHAR(spoolpath)) + 1 ] ;
  302.          strcpy ( PCHAR(SpoolPath), PCHAR(spoolpath) ) ;
  303.       }
  304.  
  305.       ~SpoolSize ( void ) {
  306.          delete [] SpoolPath ;
  307.       }
  308.  
  309.       void SetShowK ( USHORT flag ) { ShowK = flag ;  Value = 0 ; }
  310.  
  311.       int Measure ( HPS hPS, RECTL &Rectangle ) ;
  312.  
  313.       ULONG NewValue ( void ) ;
  314.  
  315.       void FormatText ( char *Label, char *Text, ULONG Value ) ;
  316.  
  317.       void Repaint ( HPS hPS, RECTL &Rectangle,
  318.          COLOR TextColor, COLOR BackColor, BOOL Mandatory ) ;
  319. } ;
  320.  
  321. class CpuLoad : public Item {
  322.  
  323.    private:
  324.       PULONG IdleCount ;
  325.       ULONG MaxCount ;
  326.  
  327.    public:
  328.       CpuLoad ( USHORT id, char *pName, char *pCurrentLabel, char *pDefaultLabel, 
  329.          Dde_Server *pDdeServer, char *Topic, ULONG maxcount, PULONG idlecount )
  330.  
  331.          : Item ( id, pName, pCurrentLabel, pDefaultLabel, pDdeServer, Topic ), 
  332.          MaxCount(maxcount), IdleCount(idlecount) { }
  333.  
  334.       int Measure ( HPS hPS, RECTL &Rectangle ) ;
  335.  
  336.       ULONG NewValue ( void ) ;
  337.  
  338.       void FormatText ( char *Label, char *Text, ULONG Value ) ;
  339.  
  340.       void Repaint ( HPS hPS, RECTL &Rectangle,
  341.          COLOR TextColor, COLOR BackColor, BOOL Mandatory ) ;
  342. } ;
  343.  
  344. class TaskCount : public Item {
  345.  
  346.    private:
  347.       HAB Anchor ;
  348.  
  349.    public:
  350.       TaskCount ( USHORT id, char *pName, char *pCurrentLabel, char *pDefaultLabel, 
  351.          Dde_Server *pDdeServer, char *Topic, HAB anchor )
  352.  
  353.          : Item ( id, pName, pCurrentLabel, pDefaultLabel, pDdeServer, Topic ), 
  354.          Anchor(anchor) { }
  355.  
  356.       int Measure ( HPS hPS, RECTL &Rectangle ) ;
  357.  
  358.       ULONG NewValue ( void ) ;
  359.  
  360.       void FormatText ( char *Label, char *Text, ULONG Value ) ;
  361.  
  362.       void Repaint ( HPS hPS, RECTL &Rectangle,
  363.          COLOR TextColor, COLOR BackColor, BOOL Mandatory ) ;
  364. } ;
  365.  
  366. class DriveFree : public Item {
  367.  
  368.    private:
  369.       COUNTRYINFO CountryInfo ;
  370.       USHORT ShowK ;
  371.       ResourceString *DriveError ;
  372.       USHORT DriveNumber ;
  373.       BOOL ShowFileSystemName ;
  374.       BYTE FileSystem [80] ;
  375.       BOOL ShowDiskLabel ;
  376.       BYTE DiskLabel [12] ;
  377.       BOOL Error ;
  378.  
  379.    public:
  380.       DriveFree ( USHORT id, char *pName, char *pCurrentLabel, char *pDefaultLabel, 
  381.          Dde_Server *pDdeServer, char *Topic, COUNTRYINFO &countryinfo, 
  382.          USHORT sk, USHORT drivenumber, ResourceString *driveerror, BOOL showfilesystemname, 
  383.          PSZ filesystem, BOOL showdisklabel, PSZ disklabel )
  384.  
  385.          : Item ( id, pName, pCurrentLabel, pDefaultLabel, pDdeServer, Topic ), 
  386.          ShowK(sk), DriveError(driveerror), DriveNumber(drivenumber),
  387.          ShowFileSystemName(showfilesystemname), ShowDiskLabel(showdisklabel), 
  388.          Error(FALSE) {
  389.  
  390.          CountryInfo = countryinfo ;
  391.          strcpy ( PCHAR(FileSystem), PCHAR(filesystem) ) ;
  392.          strcpy ( PCHAR(DiskLabel), PCHAR(disklabel) ) ;
  393.       }
  394.  
  395.       void SetShowK ( USHORT flag ) { ShowK = flag ;  Value = 0 ; }
  396.  
  397.       void SetShowFileSystemName ( BOOL showfilesystemname ) { ShowFileSystemName = showfilesystemname ;  Value = 0 ; }
  398.  
  399.       void SetShowDiskLabel ( BOOL showdisklabel ) { ShowDiskLabel = showdisklabel ;  Value = 0 ; }
  400.  
  401.       int Measure ( HPS hPS, RECTL &Rectangle ) ;
  402.  
  403.       ULONG NewValue ( void ) ;
  404.  
  405.       void FormatText ( char *Label, char *Text, ULONG Value ) ;
  406.  
  407.       void Repaint ( HPS hPS, RECTL &Rectangle,
  408.          COLOR TextColor, COLOR BackColor, BOOL Mandatory ) ;
  409. } ;
  410.  
  411. class TotalFree : public Item {
  412.  
  413.    private:
  414.       COUNTRYINFO CountryInfo ;
  415.       USHORT ShowK ;
  416.       ULONG Drives ;
  417.  
  418.    public:
  419.       TotalFree ( USHORT id, char *pName, char *pCurrentLabel, char *pDefaultLabel, 
  420.          Dde_Server *pDdeServer, char *Topic, COUNTRYINFO &countryinfo, 
  421.          USHORT sk, ULONG drives )
  422.  
  423.          : Item ( id, pName, pCurrentLabel, pDefaultLabel, pDdeServer, Topic ), 
  424.          ShowK(sk), Drives(drives) {
  425.  
  426.          CountryInfo = countryinfo ;
  427.       }
  428.  
  429.       void SetShowK ( USHORT flag ) { ShowK = flag ;  Value = 0 ; }
  430.  
  431.       void ResetMask ( ULONG drives ) { Drives = drives ; }
  432.  
  433.       int Measure ( HPS hPS, RECTL &Rectangle ) ;
  434.  
  435.       ULONG NewValue ( void ) ;
  436.  
  437.       void FormatText ( char *Label, char *Text, ULONG Value ) ;
  438.  
  439.       void Repaint ( HPS hPS, RECTL &Rectangle,
  440.          COLOR TextColor, COLOR BackColor, BOOL Mandatory ) ;
  441. } ;
  442.  
  443. class SwapSlack : public Item {
  444.  
  445.    private:
  446.       COUNTRYINFO  CountryInfo ;
  447.       USHORT       ShowK ;
  448.       VirtualFree *pVirtualFree ;
  449.       SwapFree    *pSwapFree ;
  450.       MemoryFree  *pMemFree ;
  451.  
  452.    public:
  453.       SwapSlack ( USHORT id, char *pName, char *pCurrentLabel, char *pDefaultLabel, 
  454.          Dde_Server *pDdeServer, char *Topic, COUNTRYINFO &countryinfo, 
  455.          USHORT sk, VirtualFree *pvf, SwapFree *psf, MemoryFree *pmf )
  456.  
  457.          : Item ( id, pName, pCurrentLabel, pDefaultLabel, pDdeServer, Topic ), 
  458.          ShowK(sk), pVirtualFree(pvf), pSwapFree(psf), pMemFree(pmf) {
  459.  
  460.          CountryInfo = countryinfo ;
  461.       }
  462.  
  463.       void SetShowK ( USHORT flag ) { ShowK = flag ;  Value = 0 ; }
  464.       int Measure ( HPS hPS, RECTL &Rectangle ) ;
  465.       ULONG NewValue ( void ) ;
  466.       void FormatText ( char *Label, char *Text, ULONG Value ) ;
  467.       void Repaint ( HPS hPS, RECTL &Rectangle, COLOR TextColor, COLOR BackColor, BOOL Mandatory ) ;
  468. } ;
  469.  
  470. class ProcessCount : public Item {
  471.  
  472.    private:
  473.       PULONG DQPS_Buffer ;
  474.  
  475.    public:
  476.       ProcessCount ( USHORT id, char *pName, char *pCurrentLabel, char *pDefaultLabel,
  477.          Dde_Server *pDdeServer, char *Topic )
  478.          : Item ( id, pName, pCurrentLabel, pDefaultLabel, pDdeServer, Topic ) { 
  479.  
  480.          DosAllocMem ( (PPVOID)&DQPS_Buffer, 0x10000, PAG_READ | PAG_WRITE | PAG_COMMIT | OBJ_TILE ) ;
  481.  
  482.       } /* endmethod */
  483.  
  484.       ~ProcessCount ( ) { DosFreeMem ( DQPS_Buffer ) ; }
  485.  
  486.       int Measure ( HPS hPS, RECTL &Rectangle ) ;
  487.       ULONG NewValue ( void ) ;
  488.       void FormatText ( char *Label, char *Text, ULONG Value ) ;
  489.       void Repaint ( HPS hPS, RECTL &Rectangle, COLOR TextColor, COLOR BackColor, BOOL Mandatory ) ;
  490. } ;
  491.  
  492. class ThreadCount : public Item {
  493.  
  494.    private:
  495.       PULONG DQPS_Buffer ;
  496.  
  497.    public:
  498.       ThreadCount ( USHORT id, char *pName, char *pCurrentLabel, char *pDefaultLabel,
  499.          Dde_Server *pDdeServer, char *Topic )
  500.          : Item ( id, pName, pCurrentLabel, pDefaultLabel, pDdeServer, Topic ) { 
  501.  
  502.          DosAllocMem ( (PPVOID)&DQPS_Buffer, 0x10000, PAG_READ | PAG_WRITE | PAG_COMMIT | OBJ_TILE ) ;
  503.  
  504.       } /* endmethod */
  505.  
  506.       ~ThreadCount ( ) { DosFreeMem ( DQPS_Buffer ) ; }
  507.  
  508.       int Measure ( HPS hPS, RECTL &Rectangle ) ;
  509.       ULONG NewValue ( void ) ;
  510.       void FormatText ( char *Label, char *Text, ULONG Value ) ;
  511.       void Repaint ( HPS hPS, RECTL &Rectangle, COLOR TextColor, COLOR BackColor, BOOL Mandatory ) ;
  512. } ;
  513.  
  514. #endif
  515.